﻿<include file="Public:header" />
<body class="layout">
<div id="index" >
  <div class="head"> <img src="__ROOT__/App/Vote/Static/images/top.png"/> </div>
  <include file="Public:box" /> 
  <!-- 报名 --> 
  <!--			<div class="vote" id="join">
				<img src="__ROOT__/App/Vote/Static/images/vote.png">
        		<div class="form">
        			<label>手机号</label><input type="tel" id="tel" maxlength="11"><br/>
        		</div>
        		<div class="subdiv">
        			<button class="submit">提交</button>
        		</div>
			</div>--> 
  <!-- 引导非会员注册 -->
  <if condition="$huiyuan eq 2">
    <div class="regist " id="novip">
      <div class="search-bar">
		<div class="regist-title">您还没有注册微信会员哦！</div>
	  <a href="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx30ec9e811ab3a870&redirect_uri=http://a.forcent.cn/iHuiyuan/user/Integral&response_type=code&scope=snsapi_base&state=0&from=singlemessage&isappinstalled=0&connect_redirect=1#wechat_redirect&_ts=5014">
        <button>点击注册</button>
        </a>
        <p>Tips:注册后请点击"萌宝大赛"进入报名！</p>
      </div>
    </div>
  </if>
  <!-- 报名处 -->
  <if condition="$huiyuan eq 1">
    <div class="vote" id="vip"> <!-- <img src="__ROOT__/App/Vote/Static/images/vote.png"> -->
      <div class="rank-title"><span>萌宝人气赛报名处</span></div>
      <div class="form">
        <label>宝贝姓名</label>
        <input type="text" id="name" maxlength="4">
        <br/>
        <div class="upload-pic">
          <label>上传照片</label>
          <!-- <input name="button" type="button" id="btn1" onclick="myfile.click();" class="picture" />
	        			<input type="text" id="input1" disabled="true">
						<input type="file" id="myfile" onchange="input1.value=this.value" style="display:none"> --> 
          
          <img src="__ROOT__/App/Vote/Static/images/add.png" id="btn_upload"/>
          <div id="comment-photo"></div>
        </div>
        <label>参赛宣言</label>
        <textarea  rows="5" cols="20" id="message"></textarea>
      </div>
      <div class="subdiv">
        <button class="submit" >提交</button>
      </div>
    </div>
  </if>
</div>
<input type="hidden" id="serverid">
<input type="hidden" id="localid">
<include file="Public:footer" /> 
<script src="__ROOT__/App/Vote/Static/js/mobile-upload.js"></script> 
<script charset="utf-8" type="text/javascript">
weixinShare({$signPackage},{$sharePackage});
var activityid = "{$_GET['activity_id']}";//活动ID
$(function(){
	//获取图片高度
	var h=$(".box img").css("height");
	$(".dynamic").css("line-height",parseInt(h)*0.22+"px");
	//提示转发信息
	$(".rule").click(function(){
		$(".rule-fixed").show();
	});
})
$("#comment-photo").on("click",".upload-div .close",function(){
	$(this).parent().remove();
	$("#btn_upload").css("opacity","1");
})

document.querySelector('#btn_upload').onclick = function () {
wx.chooseImage({
  count: 1, // 默认9
  success: function (res) {
	// alert(res.localIds);
   // images.localId = res.localIds;
    $("#localid").val(res.localIds);
	$('#comment-photo').append('<div class="upload-div"><img src="'+res.localIds+'" id="result"/><img src="__ROOT__/App/Vote/Static/images/close.png" class="close"></div>');
	$("#btn_upload").css("opacity","0");
	 wx.uploadImage({
		localId: res.localIds[0],
		success: function (res) {
			//alert(res.serverId);
			$("#serverid").val(res.serverId);
			//$.post('http://a.forcent.cn/ldh/api.php/index/jssdk_log', "img="+res.serverId);
		},
		fail: function (res) {
			alert(JSON.stringify(res));
		}
	});
  }
});
};
var lock = true;
$("#vip .submit").click(function(){
	var name = $("#name").val();
	var serverid = $("#serverid").val();
	var localid = $("#localid").val();
	var message = $("#message").val();
	//var picture=$("#input1").val();
	if(Util.isEmpty(name)){
		 Util.info("请填写姓名");
		 //$("#name").focus();
		 return false;
	}
	if($("#comment-photo").children().hasClass("upload-div")){}
	else{
		return Util.info("请上传照片");
	}
	if(Util.isEmpty(message)){
		Util.info("请填写您的参赛宣言");
		//$("#message").focus();
		return false;
	}
	if(lock){
		 $.post("__URL__/saveAddUser",{name:name,img:serverid,localid:localid,info:message,acid:activityid},function(json){
		
			 if(json.state > 0){
				var msg = json.showmsg ? json.showmsg : 0;
				//alert(msg);
				 window.location.href="http://a.forcent.cn/ldh/vote.php/Index/detail?id="+json.state+"&activity_id="+activityid+"&showmsg="+msg;
			 }else{
				 Util.showmsg(json.info);
			 }
		});
		lock = false;
	}
   
})
  // 5.3 上传图片
  document.querySelector('#uploadImage').onclick = function () {
    if (images.localId.length == 0) {
      alert('请先使用 chooseImage 接口选择图片');
      return;
    }
    var i = 0, length = images.localId.length;
    images.serverId = [];
    function upload() {
      wx.uploadImage({
        localId: images.localId[i],
        success: function (res) {
		alert(res.serverId);
		$.getJSON('__URL__/tt', {serverid:res.serverId}, function(json){			
			alert(json);
		})
          i++;
          alert('已上传：' + i + '/' + length);
          images.serverId.push(res.serverId);
          if (i < length) {
            upload();
          }
        },
        fail: function (res) {
          alert(JSON.stringify(res));
        }
      });
    }
    upload();
  };
	</script> 
